package com.beney.ds.sorting;

import com.beney.ds.sorting.abs.AbstractSort;

public class SelectionSort extends AbstractSort {
    private SelectionSort() {
    }

    public static void sort(Comparable[] arr) {
        if (arr == null) return;
        int len = arr.length, minIndex;
        for (int tail = 0; tail < len; ++tail) {
            minIndex = tail;
            for (int j = tail + 1; j < len; ++j) {
                if (isLess(arr, j, minIndex)) {
                    minIndex = j;
                }
            }
            swap(arr, minIndex, tail);
        }
    }
}
